<style type="text/css">
 <!--

td, tr {
    font-family: "宋体";
}
-->
</style>
<div id="frame_right">
    <div id="paging">
        分页加载中...
    </div>
    <div id='markup'>
        表格加载中... 
    </div>
</div>
<script type="text/javascript">
    function myLoadTable(){
        YAHOO.example.EnhanceFromMarkup = new function(){
            this.formatUrl = function(elCell, oRecord, oColumn, sData){
                elCell.innerHTML = "<a href='javascript:makeRequest(" + oRecord.getData("id") + ")' >" + sData + "</a>";
            };
            this.formatCtrl = function(elCell, oRecord, oColumn, sData){
                elCell.innerHTML = "";
                //<?php if ($this->group=='全站管理员' && $this->mod != '1') : ?>
                ;
                if (oRecord.getData("mode") === 0) {
                    elCell.innerHTML = "<span id='o" + oRecord.getData("id") + "'>" + "<a href='javascript:operate(" + oRecord.getData("id") + ")' >" + "审核" + "</a></span>";
                }
                else {
                    elCell.innerHTML = "已审核";
                };//<?php endif; ?>
                ;            
                elCell.innerHTML = elCell.innerHTML + " <a href='/index.php/admin/article/index/id/" + oRecord.getData("id") + "' >" + "修改" + "</a>";
                elCell.innerHTML = elCell.innerHTML + " <a href='/index.php/admin/article/operate/id/" + oRecord.getData("id") + "' >" + "删除" + "</a>";
            };
            var myColumnDefs = [{
                key: "id",
                label: "id",
                formatter: YAHOO.widget.DataTable.formatNumber,
                type: "number",
                sortable: true
            }, {
                key: "kename",
                label: "科室",
                //                formatter: YAHOO.widget.DataTable.formatCurrency,
                width: 60,
                sortable: true
            }, {
                key: "lname",
                label: "栏目",
                width: 70,
                sortable: true
            }, {
                key: "news_title",
                label: "标题",
                formatter: this.formatUrl,
                sortable: true
            }, {
                key: "time",
                label: "时间",
                sortable: true,
                minWidth: 300,
                width: 100
            }, {
                key: "username",
                label: "作者",
                sortable: true,
                width: 50
            }, {
                key: "controll",
                label: "操作",
                formatter: this.formatCtrl,
                minWidth: 100,
                sortable: false
            }];
            
            
            this.myDataSource = new YAHOO.util.DataSource("/index.php/admin/article/json/");
            this.myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSON;
            this.myDataSource.connXhrMode = "queueRequests";
            this.myDataSource.responseSchema = {
                resultsList: "news",
                fields: [{
                    key: "id",
                    parser: YAHOO.util.DataSource.parseNumber
                }, "news_title", "time", "username", "kename", "lname", {
                    key: "mode",
                    parser: YAHOO.util.DataSource.parseNumber
                }],
                metaFields: {
                    totalRecords: "totalRecords"
                }
            };
            // Set up the Paginator instance.  
            var myPaginator = new YAHOO.widget.Paginator({
                containers: ['paging'],
                pageLinks: 15,
                rowsPerPage: 30,
                rowsPerPageOptions: [30, 60,90],
                template: "<strong>{CurrentPageReport}</strong> {PreviousPageLink} {PageLinks} {NextPageLink} {RowsPerPageDropdown}"
            });
            
            
            this.myDataTable = new YAHOO.widget.DataTable("markup", myColumnDefs, this.myDataSource, {
                //                caption: "my",
                //                summary: "123",
                initialRequest: "mod/<?=$this->mod?>/",
                paginator: myPaginator,
				//    								scrollable:true,
                //									height:"10em",
                //									width:"500",
                sortedBy: {
                    key: "id",
                    colKey: 'id',
                    dir: "asc"
                }
            });
        };
    };
    var loadTable = new YAHOO.util.YUILoader();//Add the module to YUILoader
    loadTable.addModule({
        name: "dataTableBug", //module name; must be unique
        type: "js", //can be "js" or "css"
        fullpath: "/html/scripts/module/admin/dataTableBug.js", //can use a path instead, extending base path
        varName: "JSON", // a variable that will be available when the script is loaded.  Needed
        // in order to act on the script immediately in Safari 2.x and below.
        requires: ['datatable'] //if this module had dependencies, we could define here
    });
    loadTable.require(['datatable', 'dataTableBug']);
    loadTable.base = '/html/yui/build/';
    loadTable.loadOptional = true;
    loadTable.onSuccess = myLoadTable;
    loadTable.onFailure = function(msg, xhrobj){
        var m = "LOAD FAILED: " + msg;
        if (xhrobj) {
            m += ", " + YAHOO.lang.dump(xhrobj);
        };
        };
    loadTable.insert();
    
    
    
    
    
    
    
    
    
    var div = document.getElementById('container');
    
    var handleSuccess = function(o){
        if (o.responseText !== undefined) {
            layout2.getUnitByPosition('bottom').set('body', o.responseText);
        }
    }
    
    var handleFailure = function(o){
    
        if (o.responseText !== undefined) {
            div.innerHTML = "<ul><li>Transaction id: " + o.tId + "</li>";
            div.innerHTML += "<li>HTTP status: " + o.status + "</li>";
            div.innerHTML += "<li>Status code message: " + o.statusText + "</li></ul>";
        }
    }
    
    var callback = {
        success: handleSuccess,
        failure: handleFailure,
        argument: {
            foo: "foo",
            bar: "bar"
        }
    };
    
    var sUrl = "<?=$this->url(array('action'=>'get-One'))?>";
    
    function makeRequest(id){
        var request = YAHOO.util.Connect.asyncRequest('GET', sUrl + "/id/" + id, callback);
    }
    
    function operate(id){
        $.get("<?=$this->url(array('action'=>'audit'))?>", {
            id: id
        }, function(data){
            $("#o" + id).html('已审核');
        })
    }
</script>
